package controller;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import model.OrderModel;
import service.OrderService;
import service.impl.OrderServiceImpl;

/**
 * Servlet implementation class Order1Servlet
 */
@WebServlet("/servlet/Order1Servlet")
public class Order1Servlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Order1Servlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		OrderModel orderModel=new OrderModel();
		orderModel.setUsername((String) request.getSession().getAttribute("username"));
		String username=orderModel.getUsername();
		OrderService service=new OrderServiceImpl();
		try {
			List<OrderModel> orderlist=service.findByName(username);
			request.setAttribute("orderlist",orderlist);
			request.getRequestDispatcher("../userlist3.jsp").forward(request,response);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		
//		try {
//			OrderModel order=service.findByName(username);
//			request.setAttribute("ordernum",order.getOrdernum());
//			request.setAttribute("roomtype",order.getRoomtype());
//			request.setAttribute("usernames",order.getUsername());
//			request.setAttribute("allprice",order.getAllprice());
//			request.getRequestDispatcher("../userlist3.jsp").forward(request,response);
//		} catch (Exception e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
